package com.example.apkupdatedemo;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.HttpConnection;

import com.example.apkupdatedemo.Utils.FileInfo;
import com.example.apkupdatedemo.download.DownloadService;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;

public class UpdateDialogActivity extends Activity {
	public String ApkUrl = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.updatedialog);
		Intent apkDate = getIntent();
		String versionName = apkDate.getStringExtra("versionname");
		String content = apkDate.getStringExtra("content");
		ApkUrl = apkDate.getStringExtra("apkurl");
		//把要更新的版本号和内容放进来
		TextView titleVersion = (TextView) findViewById(R.id.dialog_title);
		titleVersion.setText(getResources().getString(R.string.dialog_title)+" "+versionName);
		TextView con = (TextView) findViewById(R.id.dialog_content);
		con.setText(content);
		
		
		findViewById(R.id.dialog_sure).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						finish();
						//在这里开启后台服务去下载我们的文件
						FileInfo fileInfo = new FileInfo(0, ApkUrl, "northNews.apk", 0, 0);
						Intent intent = new Intent(UpdateDialogActivity.this,DownloadService.class);
						intent.putExtra("fileinfo", fileInfo);
						startService(intent);
					}
				});
		

		findViewById(R.id.dialog_cancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						finish();
					}
				});
	}
}
